package com.zzty.txj1.controller;


import com.zzty.txj1.entity.Question;
import com.zzty.txj1.entity.SelfExam;
import com.zzty.txj1.entity.User;
import com.zzty.txj1.service.QuestionService;
import com.zzty.txj1.service.SelfExamService;
import com.zzty.txj1.service.TodayExamService;
import com.zzty.txj1.util.SplitUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/todayExam")
public class TodayExamController {

    @Autowired
    QuestionService questionService;

    @Autowired
    TodayExamService todayExamService;

    @RequestMapping(value = "/checkHomework")
    public SelfExam checkHomework(SelfExam selfExam, HttpServletRequest request){
        User user=(User)request.getSession().getAttribute("user");
        selfExam.setClassId(user.getClazzid());
        System.out.println("11  "+selfExam.toString());
        SelfExam selfExam1=todayExamService.checkHomework(selfExam);
        System.out.println("22  "+selfExam1);
        return  selfExam1;
    }

    @RequestMapping(value = "/getQuestionContent",method = RequestMethod.POST)
    public String getQuestionContent(SelfExam selfExam){
        String questionId=selfExam.getQuestionId();
        List<Integer> questionIds=new ArrayList<Integer>();
        SplitUtil splitUtil=new SplitUtil();
        questionIds=splitUtil.getSplit(questionId);
        String questions="";
        int i=1;
        for(Integer id:questionIds){
            Question question=new Question();
            question.setId(id);
            questions+="第"+i+"题："+questionService.getContentById(question)+"\n";
            i++;
        }
        return questions;
    }

}
